package com.yunxin.core.infra.persistence.converter;

import com.yunxin.core.domain.model.order.*;
import com.yunxin.core.infra.persistence.entity.order.*;
import com.yunxin.core.infra.persistence.entity.product.ProductQualityConfig;
import com.yunxin.core.utils.infra.support.request.BaseOrderDTO;
import org.mapstruct.Mapper;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Mapper(componentModel = "spring")
public interface OrderConverter {

    /**
     * do 转 entity
     *
     * @param orderUserApplyAllocationDO orderUserApplyAllocationDO
     * @return OrderUserApplyAllocation
     */
    OrderUserApplyAllocation toOrderUserApplyAllocation(OrderUserApplyAllocationDO orderUserApplyAllocationDO);

    /**
     * do 转 entity
     *
     * @param orderAllocationBelongToAccountDO orderAllocationBelongToAccountDO
     * @return OrderAllocationBelongToAccount
     */
    OrderAllocationBelongToAccount toOrderAllocationBelongToAccount(OrderAllocationBelongToAccountDO orderAllocationBelongToAccountDO);

    /**
     * do 转 entity
     *
     * @param orderUserApplyDO orderUserApplyDO
     * @return OrderUserApply
     */
    OrderUserApply toOrderUserApply(OrderUserApplyDO orderUserApplyDO);

    /**
     * do 转 entity
     *
     * @param orderUserApplyDetailDO orderUserApplyDetailDO
     * @return OrderUserApply
     */
    OrderUserApplyDetail toOrderUserApplyDetail(OrderUserApplyDetailDO orderUserApplyDetailDO);

    /**
     * entity 转 do
     *
     * @param entity entity
     * @return OrderAllocationBelongToAccountDO
     */
    OrderAllocationBelongToAccountDO formOrderAllocationBelongToAccount(OrderAllocationBelongToAccount entity);

    /**
     * entity 转 do
     *
     * @param entity entity
     * @return OrderUserApplyDO
     */
    OrderUserApplyDO formOrderUserApply(OrderUserApply entity);

    /**
     * entity 转 do
     *
     * @param entity entity
     * @return OrderUserApplyAllocationDO
     */
    OrderUserApplyAllocationDO formOrderUserApplyAllocation(OrderUserApplyAllocation entity);

    /**
     * entity 转 do
     *
     * @param entity entity
     * @return OrderUserApplyDetailDO
     */
    OrderUserApplyDetailDO formOrderUserApplyDetail(OrderUserApplyDetail entity);


    /**
     * entity 转 do
     *
     * @param entity entity
     * @return OrderUserUvDO
     */
    OrderUserUvDO formOrderUserUv(OrderUserUv entity);


    /**
     * 转换 BaseOrderDTO
     *
     * @param userApply   userApply
     * @param applyDetail applyDetail
     */
    static void converterBaseOrderDTO(BaseOrderDTO baseOrderDTO, OrderUserApply userApply, OrderUserApplyDetail applyDetail, ProductQualityConfig quality) {
        baseOrderDTO.setApplyOrderNo(userApply.getApplyOrderNo());
        baseOrderDTO.setName(userApply.getUserName());
        baseOrderDTO.setIdentityNo(userApply.getUserIdentityNo());
        baseOrderDTO.setBeOverdue(applyDetail.getBeOverdue());
        baseOrderDTO.setWorkCity(applyDetail.getWorkCity());
        baseOrderDTO.setEducationLevel(applyDetail.getEducationLevel());
        baseOrderDTO.setSocialSecurityLevel(applyDetail.getSocialSecurityLevel());
        baseOrderDTO.setAccumulationFundLevel(applyDetail.getAccumulationFundLevel());
        baseOrderDTO.setMicroLoanQuota(applyDetail.getMicroLoanQuota());
        baseOrderDTO.setSesameSeedQuota(applyDetail.getSesameSeedQuota());
        baseOrderDTO.setCreditCard(applyDetail.getCreditCard());
        baseOrderDTO.setOccupation(applyDetail.getOccupation());
        baseOrderDTO.setOccupationMonthlyIncome(applyDetail.getOccupationMonthlyIncome());
        baseOrderDTO.setHouseLevel(applyDetail.getHouseLevel());
        baseOrderDTO.setVehicleLevel(applyDetail.getVehicleLevel());
        baseOrderDTO.setInsure(applyDetail.getInsure());
        baseOrderDTO.setJdBtQuota(applyDetail.getJdBtQuota());
        baseOrderDTO.setAntCreditPayQuota(applyDetail.getAntCreditPayQuota());
        baseOrderDTO.setLoanAmount(applyDetail.getLoanAmount());
        baseOrderDTO.setLoanPeriod(applyDetail.getLoanPeriod());

        if (quality != null) {
            if (quality.getBeOverdueSwitch() == 1) {
                baseOrderDTO.setBeOverdue(quality.getBeOverdue());
            }
            if (quality.getWorkCitySwitch() == 1) {
                baseOrderDTO.setWorkCity(quality.getWorkCity());
            }
            if (quality.getEducationLevelSwitch() == 1) {
                baseOrderDTO.setEducationLevel(quality.getEducationLevel());
            }
            if (quality.getSocialSecurityLevelSwitch() == 1) {
                baseOrderDTO.setSocialSecurityLevel(quality.getSocialSecurityLevel());
            }
            if (quality.getAccumulationFundLevelSwitch() == 1) {
                baseOrderDTO.setAccumulationFundLevel(quality.getAccumulationFundLevel());
            }
            if (quality.getMicroLoanQuotaSwitch() == 1) {
                baseOrderDTO.setMicroLoanQuota(quality.getMicroLoanQuota());
            }
            if (quality.getSesameSeedQuotaSwitch() == 1) {
                baseOrderDTO.setSesameSeedQuota(quality.getSesameSeedQuota());
            }
            if (quality.getCreditCardSwitch() == 1) {
                baseOrderDTO.setCreditCard(quality.getCreditCard());
            }
            if (quality.getOccupationSwitch() == 1) {
                baseOrderDTO.setOccupation(quality.getOccupation());
            }
            if (quality.getOccupationMonthlyIncomeSwitch() == 1) {
                baseOrderDTO.setOccupationMonthlyIncome(quality.getOccupationMonthlyIncome());
            }
            if (quality.getHouseLevelSwitch() == 1) {
                baseOrderDTO.setHouseLevel(quality.getHouseLevel());
            }
            if (quality.getVehicleLevelSwitch() == 1) {
                baseOrderDTO.setVehicleLevel(quality.getVehicleLevel());
            }
            if (quality.getInsureSwitch() == 1) {
                baseOrderDTO.setInsure(quality.getInsure());
            }
            if (quality.getJdBtQuotaSwitch() == 1) {
                baseOrderDTO.setJdBtQuota(quality.getJdBtQuota());
            }
            if (quality.getAntCreditPayQuotaSwitch() == 1) {
                baseOrderDTO.setAntCreditPayQuota(quality.getAntCreditPayQuota());
            }
            if (quality.getLoanAmountSwitch() == 1) {
                baseOrderDTO.setLoanAmount(quality.getLoanAmount());
            }
            if (quality.getLoanPeriodSwitch() == 1) {
                baseOrderDTO.setLoanPeriod(quality.getLoanPeriod());
            }
        }
    }

}
